import { getToken } from '@/utils/auth'
import { CustcareWs } from '@/utils/websocket'
import { defineStore } from 'pinia'

export type CustCareUserState = {
    socket: any
}

export const custCareUserStore = defineStore('custCareUserStore', {
    state: (): CustCareUserState => {
        return {
            socket: Object
        }
    },
    actions: {
        setSocket() {
            let token = getToken() || ''
            this.socket = new CustcareWs(
                <string>import.meta.env.VITE_CUSTCARE_WS_SERVER,
                token
            )
            console.log('socket=', this.socket)
        }
    },
    getters: {
        getSocket(state) {
            return state.socket
        }
    }
})
